package com.yanqu.road.server.pb;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.yanqu.road.entity.activity.cookboy.CookBoyData;
import com.yanqu.road.entity.activity.cookboy.CookBoyFinishFood;
import com.yanqu.road.entity.activity.cookboy.CookBoyFood;
import com.yanqu.road.entity.activity.cookboy.process2.CookBoy2Dish;
import com.yanqu.road.pb.cookboy.CookBoyProto;
import java.util.Map;

public class CookBoyPb {

	public static CookBoyProto.CookBoySelfTableSyncMsg.Builder parseSelfTableSync(CookBoyData cookBoyData){
		CookBoyProto.CookBoySelfTableSyncMsg.Builder msg = CookBoyProto.CookBoySelfTableSyncMsg.newBuilder();
		msg.setActivityId(cookBoyData.getActivityId());
		msg.setIntegral(cookBoyData.getAllIntegral());
		msg.setFoodId(cookBoyData.getFinishFoodId());
		msg.setIsWorship(cookBoyData.isWorship());
		msg.setHp(cookBoyData.getHp());
		msg.setHpTime((int)(cookBoyData.getHpTime()/1000));
		Map<Integer,CookBoyFood> tableFoodMap = JSON.parseObject(cookBoyData.getTableFoodData(), new TypeReference<Map<Integer, CookBoyFood>>() {});
		for(CookBoyFood tableFood : tableFoodMap.values()){
			CookBoyProto.CookBoyFoodTempMsg.Builder tempFood = CookBoyProto.CookBoyFoodTempMsg.newBuilder();
			tempFood.setPos(tableFood.getPos());
			tempFood.setLevel((tableFood.getLevel()));
			tempFood.setFraction(tableFood.getFraction());
			msg.addFoodList(tempFood);
		}
		Map<Integer,CookBoyFinishFood> finishFoodMap = JSON.parseObject(cookBoyData.getFinishFoodData(), new TypeReference<Map<Integer, CookBoyFinishFood>>() {});
		for(CookBoyFinishFood finishFood : finishFoodMap.values()){
			CookBoyProto.CookBoyFinishFoodTempMsg.Builder tempFood = CookBoyProto.CookBoyFinishFoodTempMsg.newBuilder();
			tempFood.setId(finishFood.getIndex());
			tempFood.setFoodId((finishFood.getFoodId()));
			tempFood.setFraction(finishFood.getFraction());
			tempFood.setStatus(finishFood.getStatus());
			tempFood.setNo(finishFood.getNo());
			tempFood.setRank(finishFood.getRank());
			tempFood.setTime((int)(finishFood.getTime()/1000));
			msg.addFinishFoodList(tempFood);
		}
		return msg;
	}

	public static CookBoyProto.CookBoy2SelfDishRespMsg.Builder parseSelfDishTableMsg(CookBoyData cookBoyData){
		CookBoyProto.CookBoy2SelfDishRespMsg.Builder msg = CookBoyProto.CookBoy2SelfDishRespMsg.newBuilder();
		msg.setRet(0);
		return msg;
	}

	public static CookBoyProto.CookBoy2SelfDishSyncMsg.Builder parseSelfDishTableSync(CookBoyData cookBoyData){
		CookBoyProto.CookBoy2SelfDishSyncMsg.Builder msg = CookBoyProto.CookBoy2SelfDishSyncMsg.newBuilder();
		msg.setJoin(cookBoyData.isAble()?1:0);
		msg.setDishId(cookBoyData.getDishId());
		msg.setPickTimes(cookBoyData.getProcess());
		msg.setHp(cookBoyData.getHp());
		msg.setIntegral(cookBoyData.getAllIntegral());
		msg.setHpTime((int)(cookBoyData.getHpTime()/1000));
		msg.setIsWorship(cookBoyData.isWorship());
		Map<Integer, CookBoy2Dish> finishDishMap = JSON.parseObject(cookBoyData.getFinishFoodData(), new TypeReference<Map<Integer, CookBoy2Dish>>() {});
		for(CookBoy2Dish finishFood : finishDishMap.values()){
			CookBoyProto.CookBoy2DishTempMsg.Builder tempFood = CookBoyProto.CookBoy2DishTempMsg.newBuilder();
			tempFood.setId(finishFood.getIndex());
			tempFood.setDishId((finishFood.getDishId()));
			tempFood.setStatus(finishFood.getStatus());
			tempFood.setIntegral(finishFood.getIntegral());
			tempFood.setTableId(finishFood.getTableId());
			msg.addDishList(tempFood);
		}
		return msg;
	}


	public static CookBoyProto.CookBoy3SelfDataSyncMsg.Builder parseSelfBanquetTableSync(CookBoyData cookBoyData){
		CookBoyProto.CookBoy3SelfDataSyncMsg.Builder msg = CookBoyProto.CookBoy3SelfDataSyncMsg.newBuilder();
		msg.setActivityId(cookBoyData.getActivityId());
		msg.setJoin(cookBoyData.isAble()?1:0);
		msg.setIntegral(cookBoyData.getAllIntegral());
		msg.setIsWorship(cookBoyData.isWorship());
		return msg;
	}
}
